package com.ss.android.article.base.feature.feed.vh;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.c.FeedItemBehavior;
import com.ss.android.article.base.feature.feed.activity.InfoLayout;
import com.ss.android.article.base.feature.feed.k;
import com.ss.android.article.base.feature.model.i;
import com.ss.android.article.base.utils.ArticleHelper;
import com.ss.android.common.util.NetworkStatusMonitor;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.newmedia.a.TimeFormatter;

import java.util.concurrent.atomic.AtomicBoolean;

public final class g extends BaseFeedViewHolder implements k {
    final View.OnClickListener o;
    final View.OnClickListener p;
    private i q;
    private boolean r;
    private AtomicBoolean s;
    private int t;
    private ViewTreeObserver.OnPreDrawListener mOnPreDrawListener;
    private View.OnClickListener v;

    public g(Context context,
             NetworkStatusMonitor networkStatusMonitor,
             FeedItemBehavior feedItemBehavior,
             ArticleActionHelper articleActionHelper,
             int feedType,
             TimeFormatter timeFormatter,
             int actualItemImageWidth,
             int actualItemImageHeight,
             int actualLargeImageWidth,
             int maxLargeImageHeight,
             AtomicBoolean arg24) {
        this(context,
                networkStatusMonitor,
                feedItemBehavior,
                articleActionHelper,
                feedType,
                timeFormatter,
                actualItemImageWidth,
                actualItemImageHeight,
                actualLargeImageWidth,
                maxLargeImageHeight,
                arg24,
                (byte) 0);
    }

    private g(final Context context,
              NetworkStatusMonitor networkStatusMonitor,
              FeedItemBehavior feedItemBehavior,
              ArticleActionHelper articleActionHelper,
              int feedType,
              TimeFormatter timeFormatter,
              int actualItemImageWidth,
              int actualItemImageHeight,
              int actualLargeImageWidth,
              int maxLargeImageHeight,
              AtomicBoolean arg12,
              byte arg13) {
        super(context, networkStatusMonitor, feedItemBehavior,
                articleActionHelper, feedType, timeFormatter,
                actualItemImageWidth, actualItemImageHeight,
                actualLargeImageWidth, maxLargeImageHeight);
        this.mOnPreDrawListener = new ViewTreeObserver.OnPreDrawListener() {

            public final boolean onPreDraw() {
                boolean v0_2;
                mImage1Title.getViewTreeObserver().removeOnPreDrawListener(this);
                if (mImage1Title.getLineCount() > 2) {
                    mImage1InfoLayout.setVisibility(View.GONE);
                    mImage1InfoLayout.b();
                    mImage3InfoLayout.setVisibility(View.VISIBLE);
                    mImage3InfoLayout.setDislikeOnClickListener(o);
                    mImage3InfoLayout.setMoreActionClickListener(p);
                    InfoLayout.Info info = InfoLayout.Info.acquireInfo();
                    g(info);
                    h(info);
                    c(info);
                    b(info);
                    mImage3InfoLayout.a(info);
                    ((ViewGroup.MarginLayoutParams) mImage1Container.getLayoutParams()).bottomMargin = 0;
                    ViewGroup.LayoutParams v0_1 = mImage3InfoLayout.getLayoutParams();
                    if (!mAppData.getAppSettings().isFeedCellSpacingChange()) {
                        ((ViewGroup.MarginLayoutParams) v0_1).topMargin = ((int) UIUtils.dp2px(context, 8f));
                    } else if (mAppData.getAppSettings().isMaxCellSpacingChange()) {
                        ((ViewGroup.MarginLayoutParams) v0_1).topMargin = ((int) UIUtils.dp2px(context, 5f));
                    } else {
                        ((ViewGroup.MarginLayoutParams) v0_1).topMargin = ((int) UIUtils.dp2px(context, 6f));
                    }

                    v0_2 = false;
                } else {
                    v0_2 = true;
                }

                return v0_2;
            }
        };
        this.v = new View.OnClickListener() {
            public final void onClick(View view) {
                mFeedItemBehavior.handleItemClick(mPosition, view, new Object[0]);
            }
        };
        this.o = new View.OnClickListener() {

            public final void onClick(View arg4) {
                mFeedItemBehavior.handlePopIconClick(mPosition, arg4, 9);
            }
        };
        this.p = new View.OnClickListener() {


            public final void onClick(View arg4) {
                mFeedItemBehavior.handleMoreActionClick(mPosition, arg4, new Object[0]);
            }
        };
        this.s = arg12;
    }

    private void a(TextView tv) {
        String v1 = null;
        if (android.support.design.a.isTextEmpty(v1)) {
            tv.setVisibility(View.GONE);
        } else {
            tv.setText(v1);
            tv.setEnabled(this.mCellRef.readTs <= 0);
        }
    }

    protected final void a(InfoLayout.Info arg3) {
        String v1 = null;
        if (this.q != null && !android.support.design.a.isTextEmpty(v1)) {
            arg3.a |= 32;
            arg3.c = v1;
            arg3.labelStyle = this.mCellRef.labelStyle;
        }
    }

    final void b(InfoLayout.Info info) {
        String v1 = null;
        if ((this.mCellRef.n()) && !android.support.design.a.isTextEmpty(v1) && !android.support.design.a.isTextEmpty(v1.trim())) {
            info.a |= 1;
            info.d = v1.trim();
        }
    }

    public final boolean d() {
        return this.r;
    }

    public final void e() {
        this.r = false;
    }

    public final void loadImage() {
        ImageInfo v0;
        Object v3 = null;
        int v2 = com.ss.android.article.browser.R.id.image_info;
        if (this.t == 1) {
            v0 = ArticleHelper.getImageInfoTag(this.mImage1ImageView);
            if (v0 != null) {
                android.support.design.a.setImage(this.mImage1ImageView, v0);
                this.mImage1ImageView.setTag(v2, v3);
            }
        } else if (this.t == 2) {
            v0 = ArticleHelper.getImageInfoTag(this.mLargeImage);
            if (v0 != null) {
                android.support.design.a.setImage(this.mLargeImage, v0);
                this.mLargeImage.setTag(v2, v3);
            }
        }
    }

    protected final void g() {
        boolean v0_2;
        String v7 = null;
        int v6 = 2;
        super.g();
        this.q = this.mCellRef.F;
        if (this.q != null) {
            this.duplicatePressedRelativeLayout.setOnClickListener(this.v);
            this.t = 0;
            boolean[] v4 = new boolean[v6];
            AppData v0 = this.mAppData;
            NetworkStatusMonitor v3 = this.networkMonitor;
            if (v3 != null) {
                boolean v5 = v3.isWifiOn();
                boolean v3_1 = v3.isNetworkOn();
                int v0_1 = v0.mLoadImagePref;
                if (!v5) {
                    if ((v3_1) && v0_1 != v6) {
                        v0_2 = true;
                        v3_1 = true;
                    } else {
                        v0_2 = false;
                        v3_1 = false;
                    }
                } else {
                    v0_2 = true;
                    v3_1 = true;
                }

                v4[0] = v3_1;
                v4[1] = v0_2;
            }

            v0_2 = v4[0];
            if (!v4[1] || com.ss.android.article.base.feature.model.i.a != 0 || (android.support.design.a.isTextEmpty(v7))) {
                if (!v0_2) {
                } else if (com.ss.android.article.base.feature.model.i.b != 0) {
                } else if (this.actualLargeImageWidth <= 0) {
                } else {
                    android.support.design.a.isTextEmpty(v7);
                }
            } else {
                this.t = 1;
                this.k();
                this.mImage1Container.setVisibility(View.VISIBLE);
                ViewGroup.LayoutParams v0_3 = this.mImage1ImageView.getLayoutParams();
                if (android.support.design.a.o(this.context)) {
                    v0_3.width = com.ss.android.article.base.feature.app.a.b.f;
                    v0_3.height = com.ss.android.article.base.feature.app.a.b.g;
                } else {
                    v0_3.width = this.mImageViewWidth;
                    v0_3.height = this.mImageViewHeight;
                }

                this.mImage1ImageView.setLayoutParams(v0_3);
                ArticleHelper.setVisible(this.mImage1ImageView, new ImageInfo(v7, v7));
                if (!this.s.get()) {
                    this.loadImage();
                    this.r = false;
                } else {
                    this.r = true;
                }
            }

            if (this.t == 1) {
                this.mImage3Title.setVisibility(View.GONE);
                this.a(this.mImage1Title);
                this.mImage1InfoLayout.setVisibility(View.VISIBLE);
                this.mImage1InfoLayout.setDislikeOnClickListener(this.o);
                this.mImage1InfoLayout.setMoreActionClickListener(this.p);
                InfoLayout.Info info = InfoLayout.Info.acquireInfo();
                this.g(info);
                this.c(info);
                this.b(info);
                this.mImage1InfoLayout.a(info);
                this.mImage1Title.getViewTreeObserver().removeOnPreDrawListener(this.mOnPreDrawListener);
                this.mImage1Title.getViewTreeObserver().addOnPreDrawListener(this.mOnPreDrawListener);
                return;
            }

            this.a(this.mImage3Title);
            this.mImage3InfoLayout.setVisibility(View.VISIBLE);
            this.mImage3InfoLayout.setDislikeOnClickListener(this.o);
            this.mImage3InfoLayout.setMoreActionClickListener(this.p);
            InfoLayout.Info info = InfoLayout.Info.acquireInfo();
            this.g(info);
            this.h(info);
            this.c(info);
            this.b(info);
            if (this.t == 0) {
                ((ViewGroup.MarginLayoutParams) this.mImage3InfoLayout.getLayoutParams()).bottomMargin = ((int) UIUtils.dp2px(this.context, 16f));
                this.mImage3Title.setMaxLines(v6);
            } else if (this.t == v6) {
                ((ViewGroup.MarginLayoutParams) this.mImage3InfoLayout.getLayoutParams()).topMargin = ((int) UIUtils.dp2px(this.context, 8f));
            }

            this.mImage3InfoLayout.a(info);
        }
    }

    public final void onMovedToScrapHeap() {
        ViewGroup.LayoutParams v0;
        View.OnClickListener v6 = null;
        int v5 = 2;
        float v4 = 6f;
        super.onMovedToScrapHeap();
        this.duplicatePressedRelativeLayout.setOnClickListener(v6);
        this.r = false;
        UIUtils.setVisibility(this.mImage3Title, 0);
        if (this.t == 0) {
            this.mImage3InfoLayout.b();
            this.mImage3InfoLayout.setVisibility(View.GONE);
            v0 = this.mImage3InfoLayout.getLayoutParams();
            if (!this.mAppData.getAppSettings().isFeedCellSpacingChange()) {
                ((ViewGroup.MarginLayoutParams) v0).bottomMargin = this.context.getResources().getDimensionPixelSize(com.ss.android.article.browser.R.dimen.feed_info_layout_margin_bottom);
            } else if (this.mAppData.getAppSettings().isMaxCellSpacingChange()) {
                ((ViewGroup.MarginLayoutParams) v0).bottomMargin = ((int) UIUtils.dp2px(this.context, v4));
            } else {
                ((ViewGroup.MarginLayoutParams) v0).bottomMargin = ((int) UIUtils.dp2px(this.context, 7f));
            }

            if (this.mImage3Title == null) {
            } else {
                this.mImage3Title.setMaxLines(3);
            }
        } else {
            if (this.t == 1) {
                this.mImage1Title.setVisibility(View.VISIBLE);
                this.mImage1Container.setVisibility(View.GONE);
                this.mImage1InfoLayout.b();
                this.mImage1InfoLayout.setVisibility(View.GONE);
                this.mImage1Title.getViewTreeObserver().removeOnPreDrawListener(this.mOnPreDrawListener);
                if (this.mImage1Title.getLineCount() <= v5) {
                } else if (this.mImage3InfoLayout == null) {
                } else {
                    this.mImage3InfoLayout.b();
                    this.mImage3InfoLayout.setVisibility(View.GONE);
                    v0 = this.mImage1Container.getLayoutParams();
                    ViewGroup.LayoutParams v1 = this.mImage3InfoLayout.getLayoutParams();
                    if (this.mAppData.getAppSettings().isFeedCellSpacingChange()) {
                        if (this.mAppData.getAppSettings().isMaxCellSpacingChange()) {
                            ((ViewGroup.MarginLayoutParams) v0).bottomMargin = ((int) UIUtils.dp2px(this.context, 8f));
                            ((ViewGroup.MarginLayoutParams) v1).topMargin = ((int) UIUtils.dp2px(this.context, 5f));
                        } else {
                            ((ViewGroup.MarginLayoutParams) v0).bottomMargin = ((int) UIUtils.dp2px(this.context, 10f));
                            ((ViewGroup.MarginLayoutParams) v1).topMargin = ((int) UIUtils.dp2px(this.context, v4));
                        }
                    } else {
                        ((ViewGroup.MarginLayoutParams) v0).bottomMargin = this.context.getResources().getDimensionPixelSize(com.ss.android.article.browser.R.dimen.feed_item_vertical_margin);
                        ((ViewGroup.MarginLayoutParams) v1).topMargin = this.context.getResources().getDimensionPixelSize(com.ss.android.article.browser.R.dimen.feed_info_layout_title_gap);
                    }
                }
            } else if (this.t != v5) {
            } else {
                this.mLargeImageLayout.setVisibility(View.GONE);
                this.mImage3InfoLayout.b();
                this.mImage3InfoLayout.setVisibility(View.GONE);
                v0 = this.mImage3InfoLayout.getLayoutParams();
                if (this.mAppData.getAppSettings().isFeedCellSpacingChange()) {
                    if (this.mAppData.getAppSettings().isMaxCellSpacingChange()) {
                        ((ViewGroup.MarginLayoutParams) v0).topMargin = ((int) UIUtils.dp2px(this.context, 5f));
                    } else {
                        ((ViewGroup.MarginLayoutParams) v0).topMargin = ((int) UIUtils.dp2px(this.context, v4));
                    }
                } else {
                    ((ViewGroup.MarginLayoutParams) v0).topMargin = this.context.getResources().getDimensionPixelSize(com.ss.android.article.browser.R.dimen.feed_info_layout_title_gap);
                }
            }
        }
        if (this.t == 1) {
            if (this.mImage1ImageView != null) {
                this.mImage1ImageView.setTag(com.ss.android.article.browser.R.id.image_info, v6);
            }
        } else if (this.t == v5) {
            this.mLargeImage.setTag(com.ss.android.article.browser.R.id.image_info, v6);
        }
    }
}

